package com.example.readfiletest;

import java.util.List;
import java.util.zip.Inflater;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ZichanArrayAdapter extends ArrayAdapter {

	private int resource;
	
	public ZichanArrayAdapter(Context context, int resource, List objects) {
		super(context, resource, objects);
		this.resource = resource;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		View view = null;
		ViewHolder vh = null;
		Product product = (Product) getItem(position);
		
		if(convertView == null) {
			view = 	LayoutInflater.from(getContext()).inflate( resource, parent,false);
			vh = new ViewHolder();
			vh.barCodeTv = (TextView) view.findViewById(R.id.zichanz_barcode_tv);
			vh.zichanNameTv = (TextView) view.findViewById(R.id.zichan_name_tv);
			vh.pandianDateTv = (TextView) view.findViewById(R.id.zichan_pandian_date_tv);
			
			view.setTag(vh);
		} else {
			view = convertView;
			vh = (ViewHolder) view.getTag();
		}
		
		if(product != null) {
			vh.barCodeTv.setText(product.getBarCode());
			vh.zichanNameTv.setText(product.getProductName());
			vh.pandianDateTv.setText(product.getPandianDate());
		}
		
		
		return view;
		
	}
	
	class ViewHolder {
		TextView barCodeTv;
		TextView zichanNameTv;
		TextView pandianDateTv;
	}

}
